/*
 *
 *      Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the pig4cloud.com developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: lengleng (wangiegie@gmail.com)
 *
 */

package com.pig4cloud.pigx.admin.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pig4cloud.pigx.admin.api.entity.MechanismUser;
import com.pig4cloud.pigx.admin.api.vo.UserStatisticsVo;
import com.pig4cloud.pigx.admin.mapper.MechanismUserMapper;
import com.pig4cloud.pigx.admin.service.MechanismUserService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 四乱整治 服务实现类
 * </p>
 *
 * @author lengleng
 * @since 2018-01-20
 */
@Service
@AllArgsConstructor
@Slf4j
public class MechanismUserServiceImpl extends ServiceImpl<MechanismUserMapper, MechanismUser> implements MechanismUserService {


    private final MechanismUserMapper mapper;


    /**
     * @param
     * @return UserStatisticsVo
     * @author lfx
     * @date 2024/8/7 15:11
     * @Desc 人员配置统计查询
     **/
    @Override
    public UserStatisticsVo queryStatistics() {
        try {
            List<UserStatisticsVo.UserStatisticsMajor> majorRatios = mapper.queryStatistics();
            Long totalUsers = mapper.selectCount(null);
            UserStatisticsVo userStatisticsVo = UserStatisticsVo.builder()
                    .majorRatioList(majorRatios)
                    .sum(totalUsers.intValue())
                    .build();
            return userStatisticsVo;
        } catch (Exception e) {
            log.error("业务处理异常：{}", e.getMessage());
            throw new RuntimeException("业务处理异常", e);
        }
    }

}
